/*
 *   Copyright (c) 2010-2022, SIUFUNG
 */
package net.siufung.market.base.permit.controller.assembler;

import com.google.common.collect.Lists;
import net.siufung.core.utils.CopyUtil;
import net.siufung.market.base.permit.controller.model.vo.RolePermitVo;
import net.siufung.market.base.permit.mapper.entity.RolePermit;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Objects;

/**
 *
 * 系统角色权限表 持久层展示层组装器
 *
 * @author 陈建峰
 * @since 2022-07-05 16:14:50
 */
public class RolePermitAssembler {

    /**
     * RolePermit 转换成 RolePermitVo
     * @param rolePermit 数据库实体
     * @return RolePermitVo 视图
     */
    public static RolePermitVo from(RolePermit rolePermit){
        if(!Objects.isNull(rolePermit)){
            RolePermitVo rolePermitVo = new RolePermitVo();
            CopyUtil.copyProperties(rolePermit, rolePermitVo);
            return rolePermitVo;
        }
        return null;
    }

    /**
     * RolePermitList 转换成 RolePermitVoList
     * @param rolePermitList 数据库实体集合
     * @return List<RolePermitVo> 视图集合
     */
    public static List<RolePermitVo> fromList(List<RolePermit> rolePermitList){
        List<RolePermitVo> rolePermitVoList = Lists.newArrayList();
        if(!CollectionUtils.isEmpty(rolePermitList)){
            RolePermitVo rolePermitVo;
            for (RolePermit rolePermit: rolePermitList) {
                rolePermitVo = new RolePermitVo();
                CopyUtil.copyProperties(rolePermit, rolePermitVo);
                rolePermitVoList.add(rolePermitVo);
            }
        }
        return rolePermitVoList;
    }
}

